﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EntityDataModel;

namespace DataAccessLayer
{
    public class LogDAL
    {
        /// <summary>     
        /// Add a log entry in the database.
        /// </summary>
        public static void AddLog(String logMessage, String logLevel, String applicationName, String functionName, DateTime date)
        {
            using (liveCPEEntities context = new liveCPEEntities())
            {
                try
                {
                    context.Logs.AddObject(new Log
                    {
                        Level = logLevel,
                        ApplicationName = applicationName,
                        FonctionName = functionName,
                        LogContent = logMessage,
                        LogID = System.Guid.NewGuid(),
                        PublicationDate = date
                    });

                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame();
                    throw new Exception(sf.GetMethod().Name + " unexpected error", e);
                }
            }
        }
    }
}
